<template>
  <div>
       <el-table
        :data="bussinessInfo" style="width: 100%">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          prop='username'
          label="姓名"
          width="120">          
        </el-table-column>
        <el-table-column
          prop='password'
          label="密码"
          width="120">          
        </el-table-column>
        <el-table-column
          prop="phonenumber"
          label="电话号码"
          width="120">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="idnumber"
          label="身份证号码"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="identity"
          label="身份"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
      </el-table>
      
      <add-user 
            :addUserVisible="addUserVisible"
            @val-change="changeAddUser"
            @cancel="addUserVisible = false"
            :modalType='modalType'
            :getList='getList'
            :currentrow='currentrow'
            @closeDialog='closeDialog'
            :identityType='identityType'
        ></add-user>
  </div>
</template>

<script>
import addUser from '../../../components/content/useritem/addUser.vue';

import {deleteUser,updateUser} from '@/network/user'
export default {
  name:'bussinessHome',
  props:{
    bussinessInfo:{
      type:Array,
      default:[]
    },
    modalType:Number,
    getList:Function,
    identityType:Number
  },
  data() {
    return {
        addUserVisible : false,
        // form:{}
        currentrow:{}
    }
  },
  components:{
    addUser
  },
  
  created(){
    console.log(this.bussinessInfo);
    console.log(this.modalType);
    
  },
  methods: {
   

    // 编辑
    handleEdit(row){
      // 回显

        console.log('点击了编辑',row);
        let id = row.id
        // for(let i in row){
        //   console.log(row[i]);
        //   this.currentrow = row[i]
        // }
        this.currentrow = row
        console.log(this.currentrow);
        this.addUserVisible = true
        // updateUser({row}).then(res=>{
        //   if(res.status === 200){
        //     console.log('获取成功');
        //   }
        // })

        // console.log(JSON.parse(JSON.stringify(row)));
        // 深拷贝，否则报错
        // this.currentrow = JSON.parse(JSON.stringify(row))

        this.$emit('editBtn',this.currentrow)
       
        
        

    },
    // 删除操作
    handleDelete(row){
      console.log('点击了删除');
      console.log(row);
      let id = row.id
      console.log(id);
      deleteUser({id}).then( res =>{
        console.log('删除用户信息',id);
        console.log(res);
        if(res.status === 200){
          console.log('删除成功');
          this.getList()
        } else {
          console.log('删除失败');
        }
      })
    },
    // 编辑操作
     changeAddUser(){
        this.addUserVisible = false
      },
      // 关闭dialog
    closeDialog(){
      this.addUserVisible = !this.addUserVisible
    }
  },
}
</script>

<style>

</style>